Skip to content

feat(settings): pool database connections in web processes - #1207

Draft
tintinhamans wants to merge 3 commits into
ctrliq:mainfrom
community-outpost:feat/web-connection-pool
Draft

tintinhamans wants to merge 3 commits into
ctrliq:mainfrom
community-outpost:feat/web-connection-pool

Conversation

@tintinhamans

Copy link
Copy Markdown
SUMMARY

Follow-up to #1203, and built on it. Under uvicorn CONN_MAX_AGE can't reuse connections, so this uses Django's pool for web processes instead. Each uvicorn worker keeps 2 to 4 connections. DATABASE_POOL changes that, and False turns it off.

psycopg-pool is LGPL, so I added its source to licenses/. The license test couldn't match that tarball's name, so I fixed the matcher too.

A settings read on the event loop (#1033) blocks the loop while a thread runs the query. Requests return their connections from that loop, so with a pool that read waited on connections that couldn't come back: 30 seconds, then the default. The debug toolbar does this on every response. That thread now connects outside the pool.

5 uvicorn workers, 400 requests through 100 threads, PostgreSQL 18:

Responses Peak connections Left open after
CONN_MAX_AGE=60, before #1203 380 OK, 20 500s 298 216
#1203, one per request 400 OK 97 0
Pool 400 OK 20 20
Pool, debug toolbar on 400 OK 22 20
ISSUE TYPE
  • New or Enhanced Feature
COMPONENT NAME
  • API
ASCENDER VERSION
25.6.4.dev39+g0cf703e2

…corn

Signed-off-by: tintinhamans <5984296+tintinhamans@users.noreply.github.com>
…the pool

Signed-off-by: tintinhamans <5984296+tintinhamans@users.noreply.github.com>
Signed-off-by: tintinhamans <5984296+tintinhamans@users.noreply.github.com>
@tintinhamans tintinhamans changed the title Pool database connections in web processes feat(settings): pool database connections in web processes Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant